(function() {
	require(['jquery', 'vbox', 'select2'], function(jquery, vbox) {
		if(typeof jQuery === 'undefined') {	//检测jquery依赖项
			throw new Error('jquery依赖项未能加载');
		}
		
		if(typeof $.fn.bootstrapValidator === 'undefined') {	//检测bootstrapValidator依赖项
			throw new Error('bootstrapValidator依赖项未能加载');
		}
		
		/*所属司局下拉列表*/
		var $eventSelect1 = null, $eventSelect2 = null;
		$.ajax({
			url: 'organization/retrieveOrganizations.service',
			type: 'get',
			success: function(data) {
				var _data = data.data;
				var select2Data = $.map(_data, function (obj) {
					  obj.text = obj.text || obj.name; 
					  obj.id = obj.id;
					  return obj;
					});
				$eventSelect1 = $("#create_name").select2({
					 placeholder: "所属司局",
					 allowClear: true,
					 data: select2Data,
					 minimumResultsForSearch: Infinity
				 }).val("test_select2_null").trigger("change");
			}
		});
		
		$.ajax({
			url: 'projectCotegory/retieveProjectCotegorys.service',
			type: 'post',
			success: function(data) {
				var _data = data.data;
				var select2Data = $.map(_data, function (obj) {
					obj.text = obj.name; 
					obj.id = obj.id;
					return obj;
				});
				$eventSelect2 = $("#projectCreate_name").select2({
					placeholder: "工程名称",
					allowClear: true,
					data: select2Data,
					minimumResultsForSearch: Infinity
				}).val("test_select2_null").trigger("change");
			}
		});
		
		/*验证添加*/
		var v = vbox;
		$('#projectManagement_create_form').bootstrapValidator({
	        feedbackIcons:v.feedbackIcons,
	        fields: {
	        	targetAttribute: {
	        		trigger: 'blur',
	                validators: {
	                    notEmpty: v.notEmpty
	                }
	            },
	            pcname:{
	            	trigger: 'blur',
	                validators: {
	                    notEmpty: v.notEmpty
	                }
	            },
	            oname: {
	        		validators: {
	        			notEmpty: v.notEmpty
	        		}
	        	}
	        }
	    });
	});
})();